package com.googlecode.quillen.repository;

import java.util.List;
import java.util.ArrayList;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: greg
 * Date: Jul 11, 2009
 * Time: 4:56:52 PM
 */
public class AttributeStorageQuery implements Serializable
{
    public enum Operator
    {
        equals("="),
        lessThan("<"),
        lessThanOrEqualTo("<="),
        greaterThan(">"),
        greaterThanOrEqualTo(">="),
        like("like");

        private final String str;

        Operator(String str)
        {
            this.str = str;
        }

        public String toString()
        {
            return str;
        }
    }

    // TODO: move into ComplexCondition?
    public enum Conjunction
    {
        and,
        or
    }

    public static interface Condition
    {
    }

    public static class ComplexCondition implements Condition, Serializable
    {
        public Conjunction conjunction;
        public Condition left;
        public Condition right;

        public ComplexCondition(Condition left, Conjunction conjunction, Condition right)
        {
            this.conjunction = conjunction;
            this.left = left;
            this.right = right;
        }
    }

    // TODO: better name
    public static class LeafCondition implements Condition, Serializable
    {
        public Operator operator;
        public String attribute;
        public String value;

        public LeafCondition(String attribute, Operator operator, String value)
        {
            this.operator = operator;
            this.attribute = attribute;
            this.value = value;
        }
    }

    public static class NullCondition implements Condition, Serializable
    {
        public String attribute;

        public NullCondition(String attribute)
        {
            this.attribute = attribute;
        }
    }

    public static class NotNullCondition implements Condition, Serializable
    {
        public String attribute;

        public NotNullCondition(String attribute)
        {
            this.attribute = attribute;
        }
    }

    private List<String> projection = new ArrayList<String>();
    private Condition condition;

    public AttributeStorageQuery()
    {
        this(null);
    }

    public AttributeStorageQuery(Condition condition)
    {
        this.condition = condition;
    }

    public List<String> getProjection()
    {
        return projection;
    }

    public void setProjection(List<String> projection)
    {
        this.projection = projection;
    }

    public Condition getCondition()
    {
        return condition;
    }

    public void setCondition(Condition condition)
    {
        this.condition = condition;
    }

    public void addProjection(String attribute)
    {
        projection.add(attribute);
    }
}
